﻿namespace ConsoleApp1
{
    internal class Program
    {
        static void Main()
        {
            Console.WriteLine("你好，我是林帆\n");
            Console.WriteLine("请输入下限数字：");
            string s1 = Console.ReadLine();
            Console.WriteLine("请输入上限数字：");
            string s2 = Console.ReadLine();

            int minBound = 0;
            int maxBound = 0;

            if (string.IsNullOrWhiteSpace(s1) || string.IsNullOrWhiteSpace(s2))
            {
                Console.WriteLine("输入不能为空，请输入有效的数字。");
                return;
            }

            try
            {
                minBound = int.Parse(s1);
                maxBound = int.Parse(s2);
            }
            catch (FormatException)
            {
                Console.WriteLine("输入的不是有效的数字，请输入整数。");
                return;
            }

            Console.WriteLine($"您输入的上下限是：{minBound},{maxBound}");

            // 输出质数的逻辑
            for (int i = minBound; i <= maxBound; i++)
            {
                if (IsPrime(i))
                {
                    Console.WriteLine(i);
                }
            }
        }

        static bool IsPrime(int number)
        {
            if (number <= 1) return false;
            if (number == 2) return true;
            if (number % 2 == 0) return false;

            var boundary = (int)Math.Floor(Math.Sqrt(number));

            for (int i = 3; i <= boundary; i += 2)
            {
                if (number % i == 0) return false;
            }

            return true;
        }
    }
}
